// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: MZ Setup Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 39 : TYPE_MZSETUP

// Function declarations
reserve function MZSetup_Function93
reserve function MZSetup_Function94

// Static Values

// Tables
public table MZSetup_table0
	0x300000, 0x2640000, 0, 8, 8, 137, 56, 1, 40, 4, 8, 14, 0, 18, 8, 18, 56, 1, 40, 7, 8, 2, 0, 32, 2, 13, 0, 3, 48, 1, 32, 8, 0, 3, 8, 49, 56, 1, 40, 7, 8, 37, 56, 1, 40, 8, 8, 2, 0, 18, 4, 16, 0, 5, 48, 1, 32, 11, 8, 11, 0, 7, 4, 16, 0, 4, 8, 6, 0, 22, 8, 5, 56, 1, 40, 12, 8, 16, 0, 17, 8, 31, 0, 13, 56, 1, 40, 9, 0, 36, 8, 2, 56, 1, 40, 9, 8, 36, 0, 66, 48, 1, 32, 8, 4, 37, 0, 6, 4, 17, 52, 1, 36, 6, 4, 68, 0, 28, 2, 12, 50, 1, 34, 8, 2, 50, 0, 32, 8, 83, 56, 1, 40, 8, 8, 9, 0, 21, 56, 1, 40, 7, 8, 5, 0, 98, 8, 69, 0, 25, 8, 21, 56, 1, 40, 6, 8, 4, 0, 15, 4, 16, 0, 4, 8, 18, 56, 1, 40, 7, 8, 5, 0, 27, 8, 23, 0, 9, 48, 1, 32, 6, 0, 19, 8, 19, 0, 20, 56, 4, 40, 9, 8, 4
end table

public table MZSetup_table1
	0x300000, 0x2680000, 0, 8, 8, 41, 56, 1, 40, 3, 8, 80, 56, 1, 40, 6, 8, 7, 0, 23, 8, 21, 56, 1, 40, 5, 8, 6, 0, 15, 8, 8, 0, 17, 56, 1, 40, 5, 8, 46, 56, 1, 40, 12, 8, 30, 0, 9, 48, 1, 32, 3, 40, 3, 0, 25, 4, 4, 0, 7, 8, 3, 56, 1, 40, 7, 0, 14, 4, 18, 0, 5, 8, 5, 56, 1, 40, 9, 8, 7, 0, 24, 8, 17, 0, 12, 8, 19, 0, 3, 48, 1, 32, 7, 40, 4, 8, 12, 0, 20, 8, 17, 56, 1, 40, 10, 8, 98, 0, 7, 4, 80, 52, 1, 36, 20, 4, 2, 0, 14, 8, 21, 56, 1, 40, 10, 8, 15, 56, 1, 40, 7, 8, 59, 0, 23, 8, 6, 56, 1, 40, 6, 8, 56, 0, 27, 8, 24, 0, 17, 8, 73, 56, 1, 40, 8, 8, 23, 0, 5, 4, 25, 0, 24, 4, 36, 0, 77, 4, 35, 52, 1, 36, 7, 4, 7, 0, 13, 8, 19, 0, 53, 4, 10, 52, 1, 36, 4, 4, 16, 0, 14, 4, 8, 0, 101, 4, 4, 52, 1, 36, 2, 4, 32, 0, 14
end table

public table MZSetup_table2
	0x300000, 0x2640000, 0, 22, 8, 137, 56, 1, 40, 7, 8, 6, 0, 40, 8, 9, 56, 1, 40, 6, 8, 18, 0, 3, 4, 16, 8, 5, 56, 1, 40, 8, 8, 22, 56, 1, 40, 27, 8, 32, 56, 1, 40, 15, 8, 9, 0, 27, 48, 1, 32, 10, 40, 2, 8, 18, 0, 21, 8, 2, 56, 1, 40, 14, 32, 3, 0, 8, 4, 16, 0, 3, 8, 40, 56, 1, 40, 24, 8, 4, 0, 18, 8, 11, 56, 1, 40, 13, 8, 86, 56, 1, 40, 5, 8, 6, 56, 1, 40, 201, 8, 31, 56, 1, 40, 6, 8, 11, 0, 17, 8, 29, 0, 47, 48, 1, 32, 14, 0, 24, 4, 15, 0, 16, 8, 9, 0, 47, 48, 1, 32, 13, 40, 2, 8, 8, 56, 1, 40, 20, 9, 3, 1, 83, 9, 2, 8, 91, 0, 29, 48, 1, 32, 13, 0, 7, 48, 1, 32, 15, 33, 1
end table

public table MZSetup_table3
	0xEA00000, 0x46C0000, 0, 23, 4, 40, 0, 5, 8, 31, 56, 1, 40, 30, 8, 24, 56, 1, 40, 3, 44, 2, 36, 8, 4, 13, 0, 15, 4, 16, 0, 5, 4, 22, 52, 1, 36, 3, 4, 4, 0, 16, 4, 121, 0, 42, 8, 8, 0, 19, 0, 8, 4, 1, 0, 64
end table

public table MZSetup_table4
	0xEA00000, 0x46C0000, 0, 25, 4, 29, 52, 1, 36, 15, 4, 5, 0, 18, 8, 17, 56, 1, 40, 10, 8, 4, 56, 1, 40, 43, 8, 4, 0, 17, 4, 4, 52, 1, 36, 5, 4, 3, 0, 33, 4, 109, 0, 34, 8, 9, 0, 15, 4, 5, 0, 255, 0, 40, 48, 1, 32, 8, 0, 7, 4, 12, 
end table

function MZSetup_Function93
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("Marble_F.ogg", 0, 0x136B1, 0x1F40)
			break
		case 2
			SetMusicTrack("Marble_F.ogg", 0, 0x136B1)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		case 4
			SetMusicTrack("Marble_F.ogg", 0, 0x136B1)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function MZSetup_Function94
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("Marble.ogg", 0, 0x18434, 0x30D4)
			break
		case 2
			SetMusicTrack("Marble.ogg", 0, 0x18434)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		case 4
			SetMusicTrack("Marble.ogg", 0, 0x18434)
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


event ObjectMain
	object.frame = object.animationTimer
	object.frame /= 20
	object.animationTimer++
	object.animationTimer %= 60
	object.value2 = object.frame
	object.value2 <<= 1
	object.value2 += 440
	Copy16x16Tile(366, object.value2)
	object.value2++
	Copy16x16Tile(367, object.value2)
	switch object.frame
	case 0
		object.value2 = 460
		break
	case 1
		object.value2 = 528
		break
	case 2
		object.value2 = 596
		break
	end switch
	object.value3++
	object.value3 &= 511
	Sin(object.value1, object.value3)
	object.value1 += 512
	object.value1 >>= 2
	object.value1 &= 31
	if object.value1 > 15
		object.value1 &= 15
		object.value1 <<= 2
		object.value2 += object.value1
		Copy16x16Tile(363, object.value2)
		object.value2++
		Copy16x16Tile(362, object.value2)
		object.value2++
		Copy16x16Tile(365, object.value2)
		object.value2++
		Copy16x16Tile(364, object.value2)
	else
		object.value1 <<= 2
		object.value2 += object.value1
		Copy16x16Tile(362, object.value2)
		object.value2++
		Copy16x16Tile(363, object.value2)
		object.value2++
		Copy16x16Tile(364, object.value2)
		object.value2++
		Copy16x16Tile(365, object.value2)
	end if
	temp0 = object.value4
	temp0 >>= 4
	temp0 <<= 1
	temp0 += 446
	Copy16x16Tile(360, temp0)
	temp0++
	Copy16x16Tile(361, temp0)
	temp0++
	object.value4++
	object.value4 &= 63
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp1 = object[currentPlayer].xpos
		temp1 >>= 16
		temp2 = object[currentPlayer].ypos
		temp2 >>= 16
		temp2 += 4
		Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_ANGLEB)
		if temp0 == 1
			if object[currentPlayer].value37 != 3
				CallFunction(PlayerObject_Hit)
			end if
		end if
	next
end event


event ObjectDraw
	if screen.yoffset > 458
		temp0 = screen.yoffset
		temp0 -= 458
		temp0 *= 0xC000
		tileLayer[1].scrollPos = temp0
	else
		tileLayer[1].scrollPos = 0
	end if
end event


event ObjectStartup
	SetMusicTrack("Marble.ogg", 0, 0x18434)
	SpeedUpMusic = MZSetup_Function93
	SlowDownMusic = MZSetup_Function94
	animalType1 = TypeName[Ricky]
	animalType2 = TypeName[Rocky]
	object[10].type = TypeName[MZ Setup]
	object[10].priority = PRIORITY_ACTIVE
	object[10].drawOrder = 0
	switch stage.actNum
	case 2
		hParallax[0].scrollPos = 0x1000000
		hParallax[1].scrollPos = 0x2000000
		hParallax[2].scrollPos = 0x2000000
		hParallax[3].scrollPos = 0x2000000
		hParallax[4].scrollPos = 0x2000000
		hParallax[5].scrollPos = 0x2000000
		hParallax[6].scrollPos = 0x2000000
		break
	case 3
		hParallax[0].scrollPos = 0x4000000
		hParallax[1].scrollPos = 0x1000000
		hParallax[2].scrollPos = 0x1000000
		hParallax[3].scrollPos = 0x1000000
		hParallax[4].scrollPos = 0x1000000
		hParallax[5].scrollPos = 0x1000000
		hParallax[6].scrollPos = 0x1000000
		break
	end switch
	if options.attractMode == 1
		switch stage.playerListPos
		case 0
			if credits.screen == 0
				PlayerObject_ReplayTable = MZSetup_table0
				PlayerObject_ReplaySize = 194
				PlayerObject_ReplayLength = 0x67C
			else
				PlayerObject_ReplayTable = MZSetup_table3
				PlayerObject_ReplaySize = 56
				PlayerObject_ReplayLength = 540
			end if
			break
		case 1
			if credits.screen == 0
				PlayerObject_ReplayTable = MZSetup_table1
				PlayerObject_ReplaySize = 206
				PlayerObject_ReplayLength = 0x708
			else
				PlayerObject_ReplayTable = MZSetup_table3
				PlayerObject_ReplaySize = 56
				PlayerObject_ReplayLength = 540
			end if
			break
		case 2
			if credits.screen == 0
				PlayerObject_ReplayTable = MZSetup_table2
				PlayerObject_ReplaySize = 162
				PlayerObject_ReplayLength = 0x708
			else
				PlayerObject_ReplayTable = MZSetup_table4
				PlayerObject_ReplaySize = 62
				PlayerObject_ReplayLength = 540
			end if
			break
		end switch
		CallFunction(PlayerObject_InitReplay)
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
